package learn_design_patterns.c2.weather;

import java.util.Observable;
import java.util.Observer;

/**
 * 此布告板显示当前观测值
 * 
 * @author zhangchen
 *
 */
public class CurrentConditionsDisplay implements Observer, DisplayElement {
	private float temperature;
	private float humidity;
	private Observable weatherData;

	public CurrentConditionsDisplay(Observable weatherData) {
		this.weatherData = weatherData;
		this.weatherData.addObserver(this);
	}

	@Override
	public void display() {
		System.out.println("Current conditions: " + temperature + "F degrees and " + humidity + "% humidity.");
	}

	// @Override
	// public void update(float temp, float humidity, float pressure) {
	// this.temperature = temp;
	// this.humidity = humidity;
	// display();
	// }

	@Override
	public void update(Observable o, Object arg) {
		if (o instanceof WeatherData) {
			WeatherData weatherData = (WeatherData) o;
			this.temperature = weatherData.getTemperature();
			this.humidity = weatherData.getHumidity();
			display();
		}
	}

}
